package com.turbo.cloud.ums.web.webservice;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.turbo.cloud.core.api.R;
import com.turbo.cloud.core.api.Result;
import com.turbo.cloud.core.base.PageQuery;
import com.turbo.cloud.core.validated.InsertValidated;
import com.turbo.cloud.core.validated.UpdateValidated;
import com.turbo.cloud.ums.web.logic.SystemLogic;
import com.turbo.cloud.ums.web.model.system.UmsSystemQo;
import com.turbo.cloud.ums.web.model.system.UmsSystemVo;
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 系统信息表 前端控制器
 * </p>
 *
 * @author zhangluning
 * @since 2022-10-11
 */
@Slf4j
@RequiredArgsConstructor
@RestController
public class UmsSystemController {

    final SystemLogic systemLogic;

    /**
     * 模糊查询系统分页列表
     *
     * @param pageQuery 分页实体
     * @return Page
     */
    @PostMapping(name = "模糊查询系统分页列表", value = "/webservice/system/querySystemPageByLike")
    public Result<Page<UmsSystemVo>> querySystemPageByLike(@RequestBody PageQuery<UmsSystemQo> pageQuery) {
        Page<UmsSystemVo> pageResult = systemLogic.querySystemPageByLike(pageQuery);
        return R.result(pageResult);
    }

    /**
     * 获取单个系统
     *
     * @param id 系统ID
     * @return
     */
    @GetMapping(name = "获取单个系统", value = "/webservice/system/querySystemById")
    public Result<UmsSystemVo> querySystemById(@NotBlank(message = "系统ID不能为空") String id) {
        UmsSystemVo result = systemLogic.querySystemById(id);
        return R.result(result);
    }

    /**
     * 新增系统
     *
     * @param umsSystemQo 实体
     * @return
     */
    @PostMapping(name = "新增系统", value = "/webservice/system/createSystem")
    public Result<Boolean> createSystem(@RequestBody @Validated(InsertValidated.class) UmsSystemQo umsSystemQo) {
        boolean result = systemLogic.createSystem(umsSystemQo);
        return R.result(result);
    }

    /**
     * 修改系统
     *
     * @param umsSystemQo 实体
     * @return
     */
    @PostMapping(name = "修改系统", value = "/webservice/system/modifySystem")
    public Result<Boolean> modifySystem(@RequestBody @Validated(UpdateValidated.class) UmsSystemQo umsSystemQo) {
        boolean result = systemLogic.modifySystem(umsSystemQo);
        return R.result(result);
    }

    /**
     * 删除系统
     *
     * @param id 系统ID
     * @return
     */
    @GetMapping(name = "删除系统", value = "/webservice/system/removeSystemById")
    public Result<Boolean> removeSystemById(@NotBlank(message = "系统ID不能为空") String id) {
        boolean result = systemLogic.removeSystemById(id);
        return R.result(result);
    }
}
